# pip install python-socketio

import socketio

sio = socketio.Client()

@sio.event
def connect():
    print('Connected to the server')
    sio.emit('message', "a0001", namespace='/')
@sio.event
def disconnect():
    print('Disconnected from the server')

@sio.event
def message(data):
    print('Received message', data)

@sio.event
def error(e):
    print('Error occurred', e)

# 广播消息
@sio.on('my_response')
def my_response1(e):
    print(e)

# 房间号消息
@sio.on('room')
def my_response1(e):
    print(e)

# namespaces:为您明空间
try:
    sio.connect('http://localhost:5002',namespaces="/")
    sio.wait()
except KeyboardInterrupt:
    sio.disconnect()